/**
*  Copyright 2009-2014 by WWW.KNET.CN  All rights reserved.
*/
package com.domain.util;

import java.io.File;
import java.io.IOException;
import java.util.Date;

import org.springframework.web.multipart.MultipartFile;

/**
 * TODO(这里用一句话描述这个类的作用)
 * @author liujie
 * @date 2015年4月24日 下午5:10:23
 * 
 */
public class commonUtil {
	public static final String CURRENTUSER="currentUser";
	public static String getFilePath(String prefixPath) throws IllegalStateException, IOException{
		String suffixPath = DateUtil.dateFormat(new Date(), "yyyyMMdd") + "/";
		String path = prefixPath + suffixPath;
		File tempPath = new File(path);
		if (!tempPath.exists()) {
			tempPath.mkdirs();
		}
		return path;
	}
	public static String getFilePath(String prefixPath,MultipartFile file) throws IllegalStateException, IOException{
		if (null !=file && file.getSize()>0) {
			String savePath="";
			String newFileName = "";
			String suffixPath = "attached/"+DateUtil.dateFormat(new Date(), "yyyyMMdd") + "/";
			String path = prefixPath + suffixPath;
			File tempPath = new File(path);
			if (!tempPath.exists()) {
				tempPath.mkdirs();
			}
			newFileName = System.currentTimeMillis() + "_" + file.getOriginalFilename();
			savePath = path + newFileName;
			File updateFile = new File(savePath);
			file.transferTo(updateFile);
			return suffixPath+newFileName;	
		}
		return "";
	}
}
